package com.huaxin.device.dto.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;
import com.huaxin.hxenum.base.Describable;

/**
 * 冷却方式枚举 (Cooling Method)
 * 用于变压器、开关柜等电力设备的冷却类型定义
 */
public enum CoolingMethod implements BaseCodeEnum<String>, Describable {

    /**
     * 干式自冷（Air Natural）
     * 靠自然对流散热
     */
    AN("AN", "干式自冷", "Dry-type transformer, cooled by natural air convection"),

    /**
     * 干式风冷（Air Forced）
     * 使用风扇强制通风冷却
     */
    AF("AF", "干式风冷", "Forced air cooling with fans"),

    /**
     * 油浸自冷（Oil Natural Air Natural）
     */
    ONAN("ONAN", "油浸自冷", "Oil-immersed, naturally cooled"),

    /**
     * 油浸风冷（Oil Natural Air Forced）
     */
    ONAF("ONAF", "油浸风冷", "Oil-immersed, forced air cooling"),

    /**
     * 强迫油循环风冷（Oil Forced Air Forced）
     */
    OFAF("OFAF", "强迫油循环风冷", "Forced oil and air circulation cooling"),

    /**
     * 强迫油循环水冷（Oil Forced Water Forced）
     */
    OFWF("OFWF", "强迫油循环水冷", "Forced oil and water cooling"),

    /**
     * 水内冷（Direct Water Cooling）
     * 绕组内部通水冷却
     */
    WN("WN", "水内冷", "Direct water cooling inside windings");

    @EnumValue
    private final String code;
    private final String displayName;
    private final String description;

    CoolingMethod(String code, String displayName, String description) {
        this.code = code;
        this.displayName = displayName;
        this.description = description;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据 code 获取枚举实例
     */
    public static CoolingMethod of(String code) {
        if (code == null || code.trim().isEmpty()) return null;
        for (CoolingMethod method : values()) {
            if (method.getCode().equalsIgnoreCase(code.trim())) {
                return method;
            }
        }
        return null;
    }

    /**
     * 判断是否为有效值
     */
    public static boolean isValid(String code) {
        return of(code) != null;
    }
}